Add permission based chest placement limits#292
Add permission based chest placement limits#292YouSeeMeRunning2 wants to merge 3 commits intoBG-Software-LLC:masterfrom
Conversation
YouSeeMeRunning2
commented
Sep 20, 2025
- Added wildchests.limit.. permission system
- Added default-chest-limits config section (0=unlimited, 1+=limited, -1=disabled)
- Added enable-chest-limits config option (default: false)
- Added limit enforcement in BlockListener with lang messages
- Added ChestLimitUtils for permission and config limit checking
- Added getChestCount() method to ChestsManager API
- Fixed v1_21_5 NMS compatibility issues (might of been an issue in my project only)
- Added wildchests.limit.<type>.<amount> permission system - Added default-chest-limits config section (0=unlimited, 1+=limited, -1=disabled) - Added enable-chest-limits config option (default: false) - Added limit enforcement in BlockListener with lang messages - Added ChestLimitUtils for permission and config limit checking - Added getChestCount() method to ChestsManager API - Fixed v1_21_5 NMS compatibility issues (might of been an issue in my project only)
|
|
||
| dependencies { | ||
| paperweight.paperDevBundle("1.21.5-R0.1-SNAPSHOT") | ||
| paperweight.paperDevBundle("1.21.4-R0.1-SNAPSHOT") |
There was a problem hiding this comment.
Why did you downgrade the version?
There was a problem hiding this comment.
The changes in this file are only because you downgraded the version
| include 'NMS:v1_21_3' | ||
| include 'NMS:v1_21_4' | ||
| include 'NMS:v1_21_5' No newline at end of file | ||
| // include 'NMS:v1_21_5' // Temporarily disabled due to API incompatibilities No newline at end of file |
| .filter(chest -> chest.getPlacer().equals(placer)) | ||
| .filter(chest -> chest.getData().getName().equals(chestType)) |
There was a problem hiding this comment.
Combine both filters to a single predicate
| .filter(chest -> chest.getPlacer().equals(placer)) | ||
| .filter(chest -> chest.getData().getName().equals(chestType)) |
There was a problem hiding this comment.
Instead of comparing the names of the chestType, get the chest data of the provided chestType and check if they are equal with ==
| } | ||
|
|
||
| @Override | ||
| public int getChestCount(UUID placer, String chestType) { |
| # Enable permission-based chest placement limits. | ||
| # When enabled, players can only place a limited number of each chest type based on permissions. | ||
| # Permission format: wildchests.limit.<type>.<amount> | ||
| # For example: wildchests.limit.linked_chest.5 allows placing up to 5 linked chests | ||
| enable-chest-limits: false | ||
|
|
||
| # Default limits for each chest type when no specific permission is given. | ||
| # Set to 0 for unlimited, or any positive number for the default limit. | ||
| # Set to -1 to disable this chest type entirely. | ||
| # These only apply when enable-chest-limits is true. | ||
| default-chest-limits: | ||
| linked_chest: 0 | ||
| large_chest: 0 | ||
| sell_chest: 0 | ||
| auto_crafter: 0 | ||
| storage_unit: 0 | ||
| chunk_collector: 0 | ||
|
|
There was a problem hiding this comment.
Change this to:
chest-limits:
enabled: false
default:
- ...
|
|
||
| private ChestLimitUtils() {} | ||
|
|
||
| public static int getPlayerChestLimit(Player player, String chestType) { |
There was a problem hiding this comment.
Calling hasPlayerChestLimit and then getPlayerChestLimit are really expensive calls (in terms of performance). Optimize this
- Chest placement limits functionality
| /** | ||
| * Result class to hold both limit existence and value information | ||
| */ | ||
| public static class ChestLimitResult { |
There was a problem hiding this comment.
Rename to Result and move this down, below the method to check for limit
| } | ||
| } | ||
|
|
||
| public static ChestLimitResult getPlayerChestLimitResult(Player player, String chestDataName) { |
|
|
||
| Integer defaultLimit = WildChestsPlugin.getPlugin().getSettings().defaultChestLimits.get(chestDataName); | ||
| if (defaultLimit != null && defaultLimit != -1) { | ||
| int actualLimit = defaultLimit == 0 ? Integer.MAX_VALUE : defaultLimit; |
There was a problem hiding this comment.
You should support limit 0 - this means players won't be able to place that chest
Instead, check if the limit is non-negative.